package com.ruoyi.yipaiju.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.yipaiju.domain.DatavPoint;
import com.ruoyi.yipaiju.service.IDatavService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/yipaiju/index")
public class IndexController extends BaseController {

    private IDatavService datavService;

    /**
     *
     * @return
     */
    @GetMapping("/panel")
    public AjaxResult panel()
    {
        // 这里固定返回几个固定的值 为了后面字段修改方便
        Map<String, String> valueMap = new HashMap<>();


        valueMap.put("value01", "11");
        valueMap.put("value02", "12");
        valueMap.put("value03", "13");
        valueMap.put("value04", "14");
        valueMap.put("value05", "15");
        valueMap.put("value06", "16");
        valueMap.put("value07", "17");
        valueMap.put("value08", "18");
        valueMap.put("value09", "19");
        valueMap.put("value10", "20");

        valueMap.put("value01Day", "111");
        valueMap.put("value02Day", "11");
        valueMap.put("value03Day", "11");
        valueMap.put("value04Day", "11");
        valueMap.put("value05Day", "11");
        valueMap.put("value06Day", "11");
        valueMap.put("value07Day", "11");
        valueMap.put("value08Day", "11");
        valueMap.put("value09Day", "11");
        valueMap.put("value10Day", "11");

        return AjaxResult.success(valueMap);
    }


    @GetMapping("/invite")
    public AjaxResult invite()
    {
        int dayCount = 10;
        Long minTime = System.currentTimeMillis() - (dayCount * 24 * 60 * 60 * 1000l);
        List<DatavPoint> datavPoints = datavService.selectInviteCountDay(minTime, true);
        Map<String, String> monthMap = datavPoints.stream().collect(Collectors.toMap(DatavPoint::getTimeVal, (item) -> item.getPointVal()));
        List<DatavPoint> datavPoints1 = new ArrayList<>();
        for (int i = dayCount; i >= 0 ; i--) {
            Date date = DateUtils.addDays(new Date(), -i);
            String day = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, date);
            DatavPoint datavPoint = new DatavPoint();
            datavPoint.setTimeVal(day);
            datavPoint.setPointVal(monthMap.get(day)==null?"0":monthMap.get(day));
            datavPoints1.add(datavPoint);
        }
        List<DatavPoint> parent = new ArrayList<>();
        DatavPoint datavPoint = new DatavPoint();
        datavPoint.setPointName("有手机号");
        datavPoint.setDatavPoints(datavPoints1);
        parent.add(datavPoint);

        DatavPoint datavPoint1 = new DatavPoint();
        datavPoint1.setPointName("无手机号");
        datavPoint1.setDatavPoints(datavPoints1);
        parent.add(datavPoint1);

        return AjaxResult.success(parent);
    }

}
